home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / alib10.zip / EDREC.ASM < prev    next >
Assembly Source File  |  1994-04-07  |  32KB  |  1,309 lines

  1. ;***************************** EDREC.ASM   **********************************
  2. PAGE  70,132
  3. COMMENT 
  4.                               EDREC (Edit Records)
  5.                               Version 1.0
  6.                               --------------------
  7.  
  8.  
  9.      Purpose
  10.      -------
  11.  
  12.      EDREC is both a sample program and ALIB utility program.  Files
  13.      created by EDREC use ALIB database format which is also used by
  14.      hyper message and error displays.  This greatly simplifies the
  15.      process of creating a file of error messages or help screens.
  16.  
  17.      Using EDREC
  18.      -----------
  19.  
  20.      EDREC can be started by typing EDREC or by typing EDREC followed
  21.      with a file name.  If the file exists, EDREC will display the first
  22.      record and wait for input.  If the file does not exist the record
  23.      window will be blank.
  24.  
  25.      The data entered using EDREC is probably going to be displayed in
  26.      a window someday, so the window size should be selected to make
  27.      data entry easier.  The record window size is set by the "Config"
  28.      menu option.
  29.  
  30.      After setting the window size, select "Edit" to add or modify
  31.      records.
  32.      
  33.      Database Format
  34.      ---------------
  35.  
  36.      EDREC creates records in a window which can be configured to any size.
  37.      Each record is variable length and terminated by a null (hex 00 char).
  38.  
  39.      Compiling
  40.      ---------
  41.  
  42.      The MASM & LINK commands needed to build EDREC.EXE are:
  43.         masm edrec;
  44.         link edrec,edrec,,alib.lib;
  45.  
  46.      
  47. 
  48.  
  49.     include    mac.inc
  50.     include    common.inc
  51. ;-----------------------------------------------------------------------------
  52.     extrn    library_setup:far
  53.     extrn    lib_error_handler:far
  54.     extrn    error_handler:far
  55.     extrn    clear_screen:far
  56.     extrn    display_string:far
  57.     extrn    display_string_fill:far
  58.     extrn    put_crt_blk:far
  59.     extrn    repeat_put_crt:far
  60.     extrn    BREAK_KEY_INTERCEPT:far
  61.     extrn    change_path:far
  62.     extrn    MENU_SYSTEM:far
  63.     extrn    change_setup:far
  64.     extrn    restore_path:far
  65.     extrn    find_home_path:far
  66.     extrn    library_terminate:far
  67.     extrn    BREAK_KEY_RESTORE:far
  68.     extrn    parse_first:far
  69.     extrn    expand_filename:far
  70.     extrn    get_string:far
  71.     extrn    qget_string:far
  72.     extrn    DEC_STR_TO_WORD:far
  73.     extrn    WORD_TO_DEC_CRT:far
  74.     extrn    get_setup:far
  75.     extrn    save_window:far
  76.     extrn    restore_window:far
  77.     extrn    draw_box:far
  78.     extrn    box_shrink:far
  79.     extrn    window_string:far
  80.     extrn    yes_or_no:far
  81.     extrn    flush_keyboard:far
  82.     extrn    set_lib_colors:far
  83.     extrn    dbase_init:far
  84.     extrn    DBASE_READ:far
  85.     extrn    dbase_read_next:far
  86.     extrn    dbase_read_prev:far
  87.     extrn    dbase_append:far
  88.     extrn    dbase_replace:far
  89.     extrn    dbase_insert:far
  90.     extrn    DBASE_REMOVE:far
  91.     extrn    dbase_close:far    
  92.     extrn    window_edit:far
  93.     extrn    window_cstring:far
  94.     extrn    strlen3:far
  95.     extrn    qwarn:far
  96.     extrn    to_upper:far
  97.     extrn    message:far
  98. ;------------------------------------------------------------------------------
  99. code        segment para public 'CODE'
  100.         assume    cs:code, ds:code
  101. ;-----------------------------------------------------------------------------
  102. edit1_msg    db    ' Current Record #',0
  103. edit3_msg    db    '(alt-H) for help ',0
  104. append_msg    db    'append',0 
  105. insert_msg    db    'insert',0
  106. modify_msg    db    'modify',0
  107. exit_msg    db    'EDREC exiting, do you wish to save the changes in memory? (Y/n)',0
  108. pspseg        dw    0
  109. lib_info_ptr    dw    0
  110. lib_info_seg    dw    0
  111.  
  112. current_operation    db    0    ;0=none 1=append 2=insert 3=replace
  113. current_record        dw    1
  114. current_record_ptr    dw    0
  115. current_Record_len    dw    0
  116. null_file_flag        db    0    ;0=file empty
  117.  
  118. file_asciiz        db    40 dup (0)
  119.  
  120. box_size        label    word
  121. box_cols        db    50    ;columns
  122. box_rows        db    5    ;rows
  123.  
  124. box_location        label    word
  125.             db    14    ;column
  126.             db    5    ;row
  127.  
  128. dirty_flag        db    0    ;1=changes have been made
  129. saved_flag        db    0    ;1=file has been saved
  130.  
  131. buffer_size    equ    1000        ;largest record size
  132. buffer            db    buffer_size dup (0)
  133. buffer_ptr        dw    buffer
  134. cursor_position        dw    0
  135.  
  136. file_create_flag    db    0    ;1=create is needed
  137. string1            db    3 dup (0)
  138. string2            db    3 dup (0)
  139.  
  140. help_asciiz        db    'EDREC.HLP',0
  141.  
  142. null_file_msg        db    'The database does not contain any records'
  143.             db    ' select the EDIT and APPEND options to add'
  144.             db    ' records, or CONFIG option to change setup.'
  145.             db    0dh,0ah,0dh,0ah,'Press any key to continue',0
  146. not_yet_msg        db    'This feature not implemented at present.  '
  147.             db    ' Press any key to continue',0
  148. ;-----------------------------------------------------------------------------
  149. start:
  150.     cli
  151.     mov    cs:pspseg,es    ;save PSP segment
  152.     mov    ax,cs        ;get CODE segment
  153.     mov    ss,ax
  154.     mov    ds,ax
  155.     mov    es,ax
  156.     mov    sp,offset stack_
  157.     sti
  158.     
  159. ; next, release memory beyond the end of the program
  160. ; The  definition for ZSEG marks the
  161. ; end of the program's code, data and stack area.
  162. ; When linking be sure ZSEG is at the end of the program.
  163.  
  164.     mov    ax,zseg
  165.  
  166.     mov    bx,cs:pspseg        ;
  167.     mov    es,bx
  168.     sub    bx,ax
  169.     neg    bx            ; size of program in paragraphs
  170.     mov    ah,4Ah            ; resize memory block
  171.     int    21h
  172.  
  173.     mov    ax,cs
  174.     mov    es,ax
  175. ;
  176. ; check if enough memory free to run program
  177. ;
  178.     mov    ax,pspseg        ;pass psp segment to setup
  179.     mov    bx,0            ;number of floating point variables
  180.     call    library_setup
  181.     mov    lib_info_ptr,si        ;save ptr to library info block
  182.     mov    lib_info_seg,es         ; see COMMON.INC or LIBRARY_SETUP
  183.     cmp    ax,128
  184.     jae    got_enough_mem        ;jmp if 128k of memory avail
  185.     mov    al,7
  186.     mov    ah,fatal_return
  187.     call    lib_error_handler
  188.     jmp    exitx
  189.     
  190. got_enough_mem:
  191. ;
  192. ; clear the screen and display signon
  193. ;
  194.     mov    ah,app_text_color
  195.     mov    al,' '
  196.     call    clear_screen
  197. ;
  198. ; display copyright message
  199. ;
  200.     mov    si,offset copyright_msg
  201.     mov    ah,app_text_color
  202.     mov    dx,1008h        ;display row 16 column xx
  203.     call    display_string    
  204.     
  205.     
  206. ; prevent an unintended program crash; trap Ctrl+Break, Ctrl+C and
  207. ; Ctrl+Alt+Del key combinations
  208.  
  209. ;    call    BREAK_KEY_INTERCEPT
  210.  
  211. ;
  212. ; switch to home directory
  213. ;
  214.     push    es
  215.     call    find_home_path
  216.     mov    bx,di
  217.     call    change_path
  218.     pop    es
  219.     jnc    path_changed
  220.     mov    al,6
  221.     mov    ah,fatal_return
  222.     call    lib_error_handler
  223.     jmp    exit2
  224. path_changed:
  225.     call    read_setup
  226.     call    establish_defaults    ;set colors & see if config file avail
  227.     call    ck_for_filename
  228. ;
  229. ; read the file (initialize the database)
  230. ;
  231. init_database:
  232.     mov    dx,offset file_asciiz
  233.     call    dbase_init
  234.     mov    es,bx            ;move selector to es:
  235. ;
  236. ; if file does not exist, then ask if create ok
  237. ;
  238.     cmp    al,1            ;check if file opened ok
  239.     jbe    clear_and_display
  240.     jmp    exit            ;jmp if error opening file
  241. ;
  242. ; clear the screen and display the box
  243. ;
  244. clear_and_display:
  245.     mov    ah,_msg_text_color
  246.     mov    al,' '
  247.     call    clear_screen
  248.     mov    dx,box_location
  249.     mov    bx,box_size
  250.     mov    ah,_msg_text_color
  251.     mov    al,0            ;single line frame
  252.     call    draw_box
  253. ;
  254. ; fill box with record info.
  255. ;
  256.     mov    dx,current_record
  257.     call    DBASE_READ
  258.     cmp    al,0
  259.     je    show_rec        ;jmp if record found
  260.     cmp    dx,1            ;check if this is record 1
  261.     jne    show_rec        ;jmp if database has records
  262. ;
  263. ; current database is empty
  264. ;
  265. null_file:
  266.     apush    ds,es
  267.     mov    ax,cs
  268.     mov    ds,ax
  269.     mov    es,ax
  270.     mov    ah,cs:_msg_text_color
  271.     mov    al,0
  272.     mov    bx,0840h
  273.     mov    dx,0808h
  274.     mov    cx,1
  275.     mov    si,offset null_file_msg
  276.     mov    bp,msg_save_win+msg_restore_win+msg_anykey+msg_disp+msg_ram
  277.     call    message
  278.     apop    es,ds        
  279.     jmp    menu1            ;jmp if empty database
  280. ;
  281. ; this record is not present in the data base, ask for instructions
  282. ;
  283.  
  284. ;
  285. ; fill the box with current record contents
  286. ;   es:si point at data for display
  287. ;      cx = record length
  288. ;
  289. show_rec:
  290.     mov    null_file_flag,1    ;specify database has data
  291.     call    move_to_buffer
  292. ;
  293. ; setup to display buffer
  294. ;
  295. display_buffer:        
  296.     mov    bx,box_size
  297.     mov    dx,box_location
  298.     call    box_shrink
  299.     mov    ah,_msg_text_color    
  300.     mov    si,offset buffer
  301.     push    di
  302.     mov    di,0
  303.     call    window_cstring
  304.     pop    di
  305. ;
  306. ; display status line with record#
  307. ;
  308.     call    show_rec_status
  309. ;
  310. ; show menu bar and wait for selection
  311. ;
  312. menu1:    mov    bx,offset menu1_def
  313.     mov    ah,08h+20h        ;restore bar & return unknown keys
  314.     call    MENU_SYSTEM
  315.     cmp    cl,1            ;check if process key
  316.     jne    menu1_d2        ;jmp if not process hit
  317.     jmp    ax
  318.     jmp    menu1            ;go do it again
  319. menu1_d2:
  320.     cmp    cl,4            ;check if abort key
  321.     je    quit_j
  322.     cmp    cl,2
  323.     jne    menu1            ;jmp if unknown mouse or no key press
  324.     cmp    al,51h
  325.     je    pgdn_j
  326.     cmp    al,49h
  327.     je    pgup_j
  328.     jmp    menu1
  329.     
  330. quit_j:    jmp    quit    
  331. p